/**
 * [description]
 * @returns {[type]} [description]
 */

const fetchData = (url, cb) => {
    setTimeout(() => {
        const  data = { status: 200, data: url };
        cb(data)
    },1000);
}


const fetchDataPromisify = (url) => {
    return new Promise((resolve)=>{
        fetchData(url, (data) => {
            resolve(data);
        });
    })
}
 
function* fn () {
    let baiduData = yield fetchDataPromisify('http://www.baidu.com');

    let qqData = yield fetchDataPromisify('http://www.qq.com');

    console.log(baiduData, qqData);
}

const gen = fn();

gen.next().value.then((data)=>{
    gen.next(data).value.then((data) => {
        gen.next(data);
    });
});


// function* fn2 () {
//     const aa = yield* fn1();
//     return aa;
// }

// let gen = fn();

// for( let v of gen) {
//     console.log(v);
// }

let gen2 = fn();

console.log(gen2.next(8));
console.log(gen2.next(9));
console.log(gen2.next(10));
console.log(gen2.next(11));
console.log(gen2.next(12));


function* fn () {
    yield 1;
    yield 2;
    yield 3;

}


for( let v of fn()) {
    console.log(v);
}